#include "Enemy.h"
#include "Object3D.h"
#include "Rectangle.h"
#include <stdlib.h>
//#include <windows.h>
#include <sstream>
#include <GL/glut.h>

const float PI = 3.1415926535f;
using namespace std;

// Constructor 
Enemy::Enemy(){
	Object3D::Object3D("");
	iDirection = 0;
	ipoints = 10;
	//pmodel1 = NULL;

	// Movement variables
	fMovement = 1.5f;
	vRotation->v[2] = 180;

	rBoundingBox = new Rectangle(0.0f,0.0f,1.0f,1.0f);
}
Enemy::Enemy(string strTexturePath){
	Object3D::Object3D(strTexturePath);
	iDirection = 0;
	ipoints = 10;
	//pmodel1 = NULL;

	// Movement variables
	fMovement = 1.5f;

	rBoundingBox = new Rectangle(0.0f,0.0f,1.0f,1.0f);
}

// Main Functions
void Enemy::Update(float deltaTime){
	if (iDirection != 0){
		Enemy::Move();
	}
	rBoundingBox->SetX(vTranslation->v[0]);
	rBoundingBox->SetY(vTranslation->v[1]);
}
void Enemy::Draw(){
	glTranslatef(vTranslation->v[0],vTranslation->v[1],0.0f);	
	glScalef(vScale->v[0], vScale->v[1], vScale->v[2]); //Scale 
	glRotatef(vRotation->v[0], 1.0f, 0.0f, 0.0f); //Rotate about the x-axis
	glRotatef(vRotation->v[1], 0.0f, 1.0f, 0.0f); //Rotate about the y-axis
	glRotatef(vRotation->v[2], 0.0f, 0.0f, 1.0f); //Rotate about the z-axis
	glBegin(GL_TRIANGLES);
		
	//Pentagon
	glVertex3f(-0.5f, -0.5f, 0.0f);
	glVertex3f(0.5f, -0.5f, 0.0f);
	glVertex3f(-0.5f, 0.0f, 0.0f);
	
	glVertex3f(-0.5f, 0.0f, 0.0f);
	glVertex3f(0.5f, -0.5f, 0.0f);
	glVertex3f(0.5f, 0.0f, 0.0f);
	
	glVertex3f(-0.5f, 0.0f, 0.0f);
	glVertex3f(0.5f, 0.0f, 0.0f);
	glVertex3f(0.0f, 0.5f, 0.0f);
	
	glEnd();
	glPopMatrix(); //Undo the move
	glPushMatrix(); //Save the current state 
}

void Enemy::Move(){
	if (iDirection>0)
		vTranslation->v[0] += fMovement;
	else if (iDirection<0)
		vTranslation->v[0] -= fMovement;
	iDirection = 0;
}

Bullet Enemy::Shoot(){
	Bullet* theBullet = new Bullet();
	theBullet->Initialize(new Vec3f(vTranslation->v[0],vTranslation->v[1]-2.0f,0.0f));
	theBullet->SetDirection(-1);
	return *theBullet;
}

void Enemy::MoveDown(float fMove){
	vTranslation->v[1] -= fMove;
}

// Setters and Getters
void Enemy::SetDirection(int iDirection){
	this->iDirection = iDirection;	
}
int Enemy::GetDirection(){
	return iDirection;
}
int Enemy::GetPoints(){
	return ipoints;
}